//-------------------------------------------------------//
// Implementation of Math::Compare functions				  //	
//------------------------------------------------------//

namespace Math
{
namespace Compare
{

//-------------------------------------------------
template<typename TA, typename TB>
inline int Compare( const TA& a, const TB& b, const TA epsilon)
{
	if ( a >= b )
	{
		if ((a-epsilon)>b)
			return 1; // es mayor
		else
			return 0; // es igual
	}
	else
	{
		if ((b-epsilon)>a)
			return -1; // es menor
		else
			return 0; // es igual
	}
}

//-------------------------------------------------
template<typename T>
inline bool EqualEpsilon (const T a, const T b, const T epsilon)
{
	return ((a > b-epsilon) && (a < b+epsilon));
}

//-------------------------------------------------
template<typename T>
inline bool ZeroEpsilon (const T a, const T epsilon)
{
	return ((a > -epsilon) && (a < epsilon));
}

//-------------------------------------------------
template<typename T>
inline bool EqualRelatEpsilon (const T a, const T b, const T epsilon)
{
	T epsilon_rel = epsilon * (a + b) * Half<T>();
	return ((a > b-epsilon_rel) && (a < b+epsilon_rel));
}

//-------------------------------------------------
template<typename T>
inline bool ZeroRelatEpsilon (const T a, const T epsilon)
{
	T epsilon_rel = epsilon * a;
	return ((a > -epsilon_rel) && (a < epsilon_rel));
}

} //namespace Compare
} //namespace Math
